/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.validator;

import com.minierp.bean.BusinessBillBean;
import com.minierp.bean.ValidatorStatus;
import com.minierp.dao.BusinessBillDao;
import com.minierp.helper.EncValidatorHelper;
import com.minierp.model.BusinessBill;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

public class BusinessBillValidator implements Validator {
	private BusinessBillDao businessBillDao;

	public boolean supports(Class clazz) {
		return BusinessBillBean.class.isAssignableFrom(clazz);
	}

	public void validate(Object obj, Errors errors) {
		BusinessBillBean bean = (BusinessBillBean) obj;
		BusinessBill form = bean.getBusinessBill();
		BusinessBill existBill = null;
		if (form.getBillCode() != null && !form.getBillCode().trim().equals("")) {
			existBill = this.businessBillDao.get(form.getBillCode());
		}

		ValidatorStatus s = EncValidatorHelper.businessBillValidate(bean,
				existBill);
		if (s.isHasError()) {
			errors.rejectValue(s.getRejectName(), "", s.getRejectValue());
		}

	}

	public BusinessBillDao getBusinessBillDao() {
		return this.businessBillDao;
	}

	public void setBusinessBillDao(BusinessBillDao businessBillDao) {
		this.businessBillDao = businessBillDao;
	}
}